<template>
<div class="userAccountUpdate">
  <!--header start-->
  <header class="header-con header-w-bg">
    <router-link to="/setting/userInfo">
      <i class="back-icon"></i>
    </router-link>
    <h1 class="header-tit">用户账号</h1>
  </header>
  <!--header end-->
  <!-- content start -->
  <div class="my-page">
    <div class="actualName">
      <ul class="myData-list">
        <li class="flex-box">
          <label>用户账号</label>
          <div class="list-flex">
            <input id="userAccount" type="text" v-model="userInfo.userAccount"  placeholder="账号保存后不可修改，可用做登录">
          </div>
        </li>
      </ul>
      <p class="tip-err" style="display: block;">用户账号不能为空</p>
        <a href="javascript:void(0);" class="save-btn" @click="saveInfo">
          <div class="org-btn">保存</div>
        </a>
    </div>
  </div>
  <!-- content end -->
  <!---->
  <div class="avatar-set">
  </div>
</div>
</template>

<script>
  import axios from 'axios'
  import common from '../../../assets/js/common'
  import qs from 'qs'
  import weui from 'weui.js'

  export default {
    data () {
      return {
        userInfo: {
          userAccount: ''
        },
        result: {
          'resultCode': '',
          'resultMsg': '',
          'content': false,
          'accessToken': null
        }
      }
    },
    created: function () {
      this.userInfo.userAccount = this.$route.params.userAccount === 'null' ? '' : this.$route.params.userAccount
    },
    methods: {
      saveInfo: function () {
        let self = this
        let userId = common.userid
        let config = {
          headers: {
            'access-token': common.accesstoken,
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }
        let data = qs.stringify({
          'userId': userId,
          'userAccount': self.userInfo.userAccount,
          'nickName': '',
          'userSerName': '',
          'userName': '',
          'idCardNo': '',
          'email': '',
          'imageUrl': ''
        })
        let queryUrl = common.api.memberCenter.updateInfo
        let loading = weui.loading('加载中')
        axios.post(queryUrl, data, config).then(function (res) {
          if (res.data.resultMsg === 'success') {
            loading.hide()
            weui.toast('修改成功')
            self.$router.go(-1)
          } else {
            loading.hide()
            weui.toast('请求失败')
          }
        })
      }
    }
  }
</script>

<style lang='scss'>
  .actualName {
    margin-top: 20px;
  }

  .tip-err {
    padding: 0 16px;
    color: #ff0629;
    font-size: 1.2rem;
  }

  .actualName .save-btn {
    display: block;
    margin-top: 36px;
    padding: 0 16px;
  }
  .org-btn {
    display: inline-block;
    width: 100%;
    height: 45px;
    line-height: 45px;
    text-align: center;
    font-size: 1.7rem;
    color: #434343;
    background-image: linear-gradient(-90deg, #ffd800 0%, #ffd800 99%);
    box-shadow: 0 8px 23px 0 rgba(255, 216, 0, 0.3);
    border-radius: 45px;
  }

  .o-org-btn {
    display: inline-block;
    width: 100%;
    height: 45px;
    line-height: 45px;
    text-align: center;
    border: 1px solid #ffd800;
    font-size: 1.7rem;
    color: #ffd800;
  }
</style>
